import UiManager from "./UiManage";
import n from "./PeripheralSystemDataMgr"
import l from "./EventMgr"
import s from "./MatchGameEventType"
import c from "./AdManager"
import u, { SkillType } from "./MatchGameData"
import p from "./BasePageCtrl"
import d from "./MatchGameSystemMgr"
import h from "./UiManage"
import f from "./MatchGameAddPropPage"
import BasePageCtrl from "./BasePageCtrl";

const { ccclass, property } = cc._decorator;

@ccclass
export default class MatchGameAddPropPageCtrl extends BasePageCtrl {
    ui = null;
    skillType = null;

    onLoad() {
        this.onUILoad();
        this.addButtonListen();
        super.onLoad();
    }

    onUILoad() {
        this.ui = this.node.addComponent(f);
    }

    addButtonListen() {
        UiManager.addButtonListen(this.ui.btn_close, this.clickClose, this);
        UiManager.addButtonListen(this.ui.btn_getProp, this.getPropCallback, this);
    }

    _init(e?) {
        var t = e.type;
        this.skillType = t;
        var a = 5, o = "", i = "";
        if (t == SkillType.Hammer) {
            a = 5;
            o = "imgs/game/matchMain/addPropPage/addPro_title_2";
            i = "消灭任意一“格”物品! ";
        } else if (t == SkillType.Gun) {
            a = 3;
            o = "imgs/game/matchMain/addPropPage/addPro_title_1";
            i = "消灭任意一“竖”物品! ";
        } else if (t == SkillType.Arrow) {
            a = 3;
            o = "imgs/game/matchMain/addPropPage/addPro_title_3";
            i = "消灭任意一“横”物品! ";
        }
        this.ui.lab_addCount.getComponent(cc.Label).string = "x" + a;
        UiManager.loadSpriteFrameInDeepPath(this.ui.title_spr.getComponent(cc.Sprite), o);
        var r = "imgs/game/matchMain/" + u.getSkillName(t);
        UiManager.loadSpriteFrameInDeepPath(this.ui.spr_prop.getComponent(cc.Sprite), r);
        this.ui.lab_dis.getComponent(cc.Label).string = i;
    }

    getPropCallback() {
        var e = this;
        n.reportEncourageVideo();
        c.getInstance().playNormalVideoAd(function (result) {
            if("success" == result){
                d.addPropVideo(e.skillType, function () {
                    l.trigger(s.SET_FIRST_SKILL, e.skillType);
                    e.hide();
                });
            }else{
                e.hide();
            }
        }, function () {
            e.hide();
         },7);
    }

    clickClose() {
        this.hide();
    }
}
